/*
 * @Author: lineCode
 * @Date: 2025-06-26 18:23:26
 * @LastEditors: lineCode 1145938682@qq.com
 * @LastEditTime: 2025-09-04 12:30:12
 * @FilePath: /shorthand-go/httpServer/controller/qixiang/qixiang.go
 */
package qixiang

import (
	"net/http"
	"shorthand-go/dao/model"
	"shorthand-go/httpServer/structs"

	"github.com/gin-gonic/gin"
)

func Notify(ctx *gin.Context) {
	// 接收参数
	notify := structs.NotifyReq{}
	if err := ctx.ShouldBind(&notify); err != nil {
		ctx.String(http.StatusOK, "failure")
		return
	}
	// 验证支付状态
	if notify.TradeStatus != "TRADE_SUCCESS" {
		ctx.String(http.StatusOK, "failure")
		return
	}

	orderModel := model.NewSysOrderModel(ctx)
	// 获取订单信息
	order, err := orderModel.FindOne(notify.OutTradeNo)
	if err != nil {
		ctx.String(http.StatusOK, "failure")
		return
	}
	// 更新订单信息
	err = orderModel.Update(notify.OutTradeNo)
	if err != nil {
		ctx.String(http.StatusOK, "failure")
		return
	}

	// 获取推荐码
	if len(order.RecommendCode) > 0 {
		// 生成要转账佣金记录
	}

	ctx.String(http.StatusOK, "success")
}
